package com.arui.springsecuritystudy.controller;

import com.arui.springsecuritystudy.dto.UserDTO;
import com.arui.springsecuritystudy.service.LoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.zyr.common.Result;

/**
 * @Description TODO
 * @Date 2024/3/28 17:20
 * @Created by 10574
 */
@RestController()
@RequestMapping("/user")
@RequiredArgsConstructor
public class LoginController {
    private final LoginService loginService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody UserDTO userDTO) throws Exception {
        final String token = loginService.login(userDTO);
        return Result.ok("登录成功", token);
    }

    @PostMapping("/logout")
    public Result<String> logout() {
        loginService.logout();
        return Result.ok("登出成功", null);
    }
}
